package com.mall.common.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.servers.Server;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@EnableConfigurationProperties(Knife4jProperties.class)
@AutoConfiguration
public class Knife4jAutoConfig {

    @Bean
    @ConditionalOnMissingBean
    public OpenAPI customOpenAPI() {
        System.out.println("《《《《《《《《《《《《《正常创建swaggerAPI路径：/doc.html?group=default#/home》》》》》》》》》》》》》》");
        return new OpenAPI()
                .addServersItem(new Server().url("http://localhost:8080").description("开发环境"))
                .addServersItem(new Server().url("").description("生产环境"))
                .info(new Info()
                        .title("优购商城用户服务接口文档")
                        .version("1.0.0")
                        .description("优购商城购物车用户文档")
                        .termsOfService("API服务条款")
                        .contact(new Contact()
                                .name("闲鱼")
                                .email("15387773197@qq.com")
                                .url("https://yourcompany.com/support"))
                        .license(new io.swagger.v3.oas.models.info.License()
                                .name("Apache 2.0")
                                .url("https://www.apache.org/licenses/LICENSE-2.0.html")));
    }
    @Bean
    @ConditionalOnMissingBean
    public GroupedOpenApi controllerGroup(Knife4jProperties properties) {
        return GroupedOpenApi.builder()
                .group(properties.getGroup())
                .packagesToScan(properties.getPackagesToScan())
                .build();
    }
}
